def find_permutation(str1, pattern):
  start = 0
  result = False
  windows_map = {}
  pattern_map = {}

  for i in pattern:
    if(i not in pattern_map ):
      pattern_map[i] = 0
    pattern_map[i] += 1
  

  for end in range(len(str1)):
    right_letter = str1[end]
    if(right_letter not in windows_map ):
      windows_map[right_letter] = 0
    windows_map[right_letter] += 1
       
    while((end-start+1)>len(pattern)):
      left_letter = str1[start]
      windows_map[left_letter] -= 1
      if(windows_map[left_letter] == 0):
        del windows_map[left_letter]
      start += 1

    if(pattern_map == windows_map):
      result = True

  # TODO: Write your code here
  return result


def main():
    print('Permutation exist: ' + str(find_permutation("oidbcaf", "abc")))
    print('Permutation exist: ' + str(find_permutation("odicf", "dc")))
    print('Permutation exist: ' + str(find_permutation("bcdxabcdy", "bcdyabcdx")))
    print('Permutation exist: ' + str(find_permutation("aaacb", "abc")))


main()